const Koa = require("koa");
const Router = require("koa-router");
const views = require("koa-views");
let app = new Koa();
let router = new Router();
app.use(views(__dirname+"/views"),{
    extension:"pug"
});
router.get("/",async (ctx,next)=>{
    // ctx.body = "新闻页面";
    ctx.redirect("/index");
});
router.get("/index",async (ctx,next)=>{
    // ctx.body = "新闻页面";
   await ctx.render("index.pug");
});
router.get("/detail",async (ctx,next)=>{
    ctx.body = "详细页面";
});
// get: 地址栏； script src=""  img src  href=""
router.all("/getData/:id",async (ctx,next)=>{
    console.log(ctx.params.id);
    ctx.body = {
        name:"张三",
        age:20
    };
});

app.use(router.routes());
app.listen(8888);